package com.springboot.rabbitmq.publisher;

import com.springboot.config.ProviderConfig;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户消息发送者
 *
 * @author supu
 * @create 2019-01-28 9:56
 **/
@Log4j2
@Component
public class UserRabbitMqPublisher {
    @Autowired
    private AmqpTemplate amqpTemplate;
    @Autowired
    private ProviderConfig providerConfig;

    public void sendUserMessage(String message) {
        log.info("userRabbitMqPublisher 要发送的消息：{}", message);
        amqpTemplate.convertAndSend(providerConfig.getString(ProviderConfig.RABBITMQ_EXCHANGE_NAME),
                providerConfig.getString(ProviderConfig.RABBITMQ_ROUTING_KEY), message);
    }
}
